# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=librocket
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r559.e6a9715
pkgrel=1
pkgdesc="The HTML/CSS User Interface Library (mingw-w64)"
arch=('any')
url="https://librocket.com/"
license=("MIT")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-python2"
         "${MINGW_PACKAGE_PREFIX}-sfml")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "make" "git")
options=('staticlibs' 'strip')
source=("${_realname}"::"git+https://github.com/libRocket/libRocket.git"
        "001-dll-exports.patch"
        "002-fix-cast-errors.patch"
        "003-fix-typo.patch")
sha256sums=('SKIP'
            '8250231717d27f275d68b291c9d05aaad437efb44208d2777809a764cf447d4a'
            'a18475b4bcacec3cde638c53190ab52ea20ac05a0bb058e842a4cfbda5c6aee7'
            '6d7976046f3c8d6bf8c5a5ffee4c187231759c351d776763941d04a363fe1a03')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}/${_realname}"
  #patch -p1 -i ${srcdir}/001-dll-exports.patch
  patch -p1 -i "$srcdir"/002-fix-cast-errors.patch
  patch -p1 -i "$srcdir"/003-fix-typo.patch
}

build() {
  [[ -d build-${CARCH} ]] && rm -rf build-${CARCH}
  mkdir -p "${srcdir}/build-${CARCH}"
  cd "${srcdir}/build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_PYTHON_BINDINGS=ON \
    -DBUILD_SHARED_LIBS=ON \
    -DPYTHON_EXECUTABLE=${MINGW_PREFIX}/bin/python2.exe \
    -DBUILD_SAMPLES=ON \
    -DCMAKE_GNUtoMS=0 \
    ../${_realname}/Build

  make
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR=${pkgdir} install
}
